<template>
  <div class='search'>
    <f-drawer ref='payDetailsDrawer' title='结算费用申请明细' :show-footer='false' width='87%' @visibleChange='visibleChange'>
      <settle-details ref='form1' :invoiceApply='invoiceApply' :invoiceData='invoiceData' :columns='columns' v-if='drawerVisible' :multiple='multiple'></settle-details>
    </f-drawer>
  </div>
</template>
<script>

import SettleDetails from "./settle_details"

export default {
  name: "SettleDetailsDrawer",
  props: {
    multiple: {
      type: Boolean,
      default: true
    }
  },
  data() {
    return {
      refs: this.$refs,
      drawerVisible: false,
      isEdit: false,
      title: "",
      invoiceApply: 0,
      invoiceData: null,
      current: "form1",
      formData: {},
      columns: null,
      forms: [
        "form1"
      ]
    }
  },
  methods: {
    showDrawer(data) {
      this.formData = data
      this.columns = this.getCol(data)
      this.invoiceApply = data.invoiceApply
      this.invoiceData = data
      this.refs["payDetailsDrawer"].show(data)
      this.$nextTick(() => {
        this.refs["form1"].setData(this.formData)
      })
    },
    handleSubmit(callback) {
      this.refs[this.current].handleSubmit(callback)
    },
    visibleChange(drawerVisible) {
      if (drawerVisible == false) {
        this.$emit("success")
      }
      this.drawerVisible = drawerVisible
    },
    getCol(data) {
      let settleFlag = !(data.settleType == 1)
      let settleFlagD = !(data.settleType == 2)
      let settleFlagC = !(data.settleType == 3)
      let settleFlagE = !(data.settleType == 4)
      let invoiceApply = this.invoiceApply
      return [
        {
          title: "序号",
          width: "60px",
          align: "center",
          fixed: "left",
          dataIndex: "rowIndex",
          customRender: function(text, record, index) {
            return (record.rowIndex !== "合计") ? (parseInt(index) + 1) : record.rowIndex
          }
        },
        {
          title: "发(退)货单号",
          align: "center",
          width: "130px",
          fixed: "left",
          dataIndex: "outOrderNo"
        },
        {
          title: "发(退)货日期",
          align: "center",
          fixed: "left",
          sorter: true,
          dataIndex: "sendDate"
        },
        {
          title: "结算对象",
          align: "center",
          width: "80px",
          ellipsis: true,
          sorter: true,
          dataIndex: "saleManName"
        },
        {
          title: "业务员编码",
          align: "left",
          width: "100px",
          dataIndex: "businessCode"
        },
        {
          title: "部门名称",
          align: "left",
          width: "100px",
          sorter: true,
          dataIndex: "deptName"
        },
        {
          title: "订单类型",
          align: "center",
          width: "80px",
          dataIndex: "orderType",
          scopedSlots: { customRender: "orderType" }
        },
        {
          title: "商品类型",
          align: "center",
          width: "80px",
          dataIndex: "drugType",
          scopedSlots: { customRender: "drugType" }
        },
        {
          title: "发货方式",
          align: "center",
          width: "80px",
          dataIndex: "sendType",
          scopedSlots: { customRender: "sendType" }
        },
        {
          title: "单位名称",
          align: "left",
          width: "130px",
          ellipsis: true,
          sorter: true,
          dataIndex: "customName"
        },
        {
          title: "商品名称",
          align: "left",
          ellipsis: true,
          sorter: true,
          width: "140px",
          dataIndex: "drugsName"
        },
        {
          title: "规格",
          align: "left",
          width: "80px",
          ellipsis: true,
          dataIndex: "drugsSpec"
        },
        {
          title: "批号",
          align: "left",
          width: "80px",
          ellipsis: true,
          dataIndex: "drugLotNo"
        },
        {
          title: "回款金额",
          align: "center",
          width: "80px",
          needTotal: true,
          dataIndex: "returnAmount"
        },
        {
          title: "回款日期",
          align: "center",
          width: "120px",
          sorter: true,
          dataIndex: "returnDate"
        },
        {
          title: "数量",
          align: "center",
          width: "80px",
          dataIndex: "saleNum"
        },
        {
          title: "单价",
          align: "center",
          type: 10,
          dataIndex: "salePrice"
        },
        {
          title: "销售金额",
          align: "center",
          width: "80px",
          needTotal: true,
          type: 10,
          dataIndex: "saleAmount"
        },
        {
          title: "渠道商",
          align: "center",
          fixed: "right",
          hidden: settleFlag,
          children: [
            {
              title: "结算价",
              align: "center",
              type: 10,
              width: "80px",
              dataIndex: "settlePrice"
            },
            {
              title: "结算标准",
              align: "center",
              type: 10,
              width: "80px",
              dataIndex: "settleRate"
            },
            {
              title: "结算金额",
              align: "center",
              width: "80px",
              needTotal: true,
              type: 10,
              dataIndex: "settleAmount"
            },{
              title: "超期差额",
              align: "center",
              width: "80px",
              needTotal: true,
              type: 10,
              dataIndex: "overDateAmount"
            }
          ]
        },
        {
          title: "片区服务商",
          align: "center",
          fixed: "right",
          hidden: settleFlagC,
          children: [
            {
              title: "结算价",
              align: "center",
              fixed: "right",
              width: "80px",
              type: 10,
              dataIndex: "settlePriceC"
            },
            {
              title: "结算标准",
              align: "center",
              fixed: "right",
              width: "80px",
              type: 10,
              dataIndex: "settleRateC"
            },
            {
              title: "结算金额",
              align: "center",
              width: "80px",
              fixed: "right",
              type: 10,
              needTotal: true,
              dataIndex: "settleAmountC"
            }
          ]
        },
        {
          title: "商务经理",
          align: "center",
          fixed: "right",
          hidden: settleFlagD,
          children: [
            {
              title: "结算价",
              align: "center",
              width: "80px",
              fixed: "right",
              type: 10,
              dataIndex: "settlePriceD"
            },
            {
              title: "结算标准",
              align: "center",
              fixed: "right",
              width: "80px",
              type: 10,
              dataIndex: "settleRateD"
            },
            {
              title: "结算金额",
              align: "center",
              width: "80px",
              type: 10,
              needTotal: true,
              dataIndex: "settleAmountD"
            },
          ]
        },
        {
          title: "商务总负责人",
          align: "center",
          fixed: "right",
          hidden: settleFlagE,
          children: [
            {
              title: "结算价",
              align: "center",
              fixed: "right",
              width: "80px",
              type: 10,
              dataIndex: "settlePriceE"
            },
            {
              title: "结算标准",
              align: "center",
              width: "80px",
              fixed: "right",
              type: 10,
              dataIndex: "settleRateE"
            },
            {
              title: "结算金额",
              align: "center",
              width: "80px",
              type: 10,
              needTotal: true,
              dataIndex: "settleAmountE"
            },
          ]
        },
        {
          title: "操作",
          align: "center",
          width: "60px",
          dataIndex: "action",
          fixed: "right",
          scopedSlots: { customRender: "action" }
        }
      ]
    },
    tabClick(name) {
      this.current = name
      this.$nextTick(() => {
        this.refs[this.current].setData(this.formData)
      })
    }
  },
  created() {
  },
  components: { SettleDetails }
}
</script>

<style scoped lang='less' rel='stylesheet/less'>

</style>
